package com.keensense.vcm.internal;

import com.keensense.vcm.HttpMethod;
import com.keensense.vcm.common.auth.CredentialsProvider;
import com.keensense.vcm.common.comm.RequestMessage;
import com.keensense.vcm.common.comm.ServiceClient;
import com.keensense.vcm.model.ListCameraRequest;
import com.keensense.vcm.model.ListCameraResponse;

import java.util.HashMap;
import java.util.Map;

import static com.keensense.vcm.common.parser.ResponseParsers.listCameraResponseParser;

public class CameraOperation extends VCMOperation {

    public CameraOperation(ServiceClient client, CredentialsProvider credsProvider) {
        super(client, credsProvider);
    }


    public ListCameraResponse listCamera(ListCameraRequest request) {
        Map<String, String> parameters = new HashMap<>();
        if (request.getSn() != null) {
            parameters.put("sn", request.getSn());
        }
        if (request.getName() != null) {
            parameters.put("name", request.getName());
        }
        if (request.getAddress() != null) {
            parameters.put("address", request.getAddress());
        }
        if (request.getCameraState() != null) {
            parameters.put("camera-state", String.valueOf(request.getCameraState().getCode()));
        }
        if (request.getCameraUse() != null) {
            parameters.put("camera-use", String.valueOf(request.getCameraUse().getValue()));
        }
        if (request.getCameraType() != null) {
            parameters.put("camera-type", String.valueOf(request.getCameraType().getValue()));
        }
        if (request.getCameraFeature() != null) {
            parameters.put("camera-feature", String.valueOf(request.getCameraFeature().getValue()));
        }
        parameters.put("page", String.valueOf(request.getPage()));
        parameters.put("limit",String.valueOf(request.getLimit()));

        RequestMessage requestMessage = new VCMRequestMessageBuilder(getInnerClient()).setEndpoint(endpoint)
                .setParameters(parameters).setMethod(HttpMethod.GET).build();
        requestMessage.setResourcePath(VCMResourcePathConstants.LIST_CAMERA);
        return doOperation(requestMessage, listCameraResponseParser, true);
    }
}
